import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 noCache: true                if set true, the page will no be cached(default is false)
 affix: true                  if set true, the tag will affix in the tags-view
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  // {
  //   path: '/graph-list',
  //   component: Layout,
  //   redirect: '/application-manage/service-group-list',
  //   children: [
  //     {
  //       path: 'graph-list',
  //       component: () => import('@/views/appstore/graph/graphList.vue'),
  //       name: 'GraphList',
  //     }
  //   ]
  //   // path: '/graph-list',
  //   // name: 'GraphList',
  //   // component: () => import('@/views/appstore/graph/graphList.vue')
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {title: '首页', icon: 'dashboard', affix: true}
      }
    ]
  },

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */

export const asyncRoutes = [
  // {
  //   path: '/graph',
  //   component: graphList,
  //   children: [
  //     {
  //       path: 'graph',
  //       component: () => import('@/views/appstore/graph/graphList'),
  //       name: 'graph',
  //       meta: {title: 'graph', icon: 'bug'}
  //     }
  //   ]
  // },
]

// export const asyncRoutes = [
//   {
//     path: '/appstore',
//     component: Layout,
//     redirect: '/appstore/service-package',
//     alwaysShow: true, // will always show the root menu
//     name: 'AppStore',
//     meta: {
//       title: '应用商店',
//       icon: 'lock'
//       // roles: ['admin', 'editor'] // you can set roles in root nav
//     },
//     children: [
//       {
//         path: 'service-package',
//         component: () => import('@/views/appstore/ServicePackage.vue'),
//         name: 'ServicePackage',
//         meta: {
//           title: '服务包'
//         }
//       },
//       {
//         path: 'service-deploy',
//         component: () => import('@/views/appstore/components/ServiceDeploy'),
//         name: 'ServiceDeploy',
//         meta: { title: '服务部署', noCache: true, activeMenu: '/appstore/service-package' },
//         hidden: true
//       },
//       {
//         path: 'service-package-detail',
//         component: () => import('@/views/appstore/components/ServicePackageDetail'),
//         name: 'ServicePackageDetail',
//         meta: { title: '服务详情', noCache: true, activeMenu: '/appstore/service-package' },
//         hidden: true
//       },
//       {
//         path: 'service-group',
//         component: () => import('@/views/appstore/ServiceGroup.vue'),
//         name: 'ServiceGroup',
//         meta: {
//           title: '服务组'
//         }
//       },
//       {
//         path: 'create-service-group',
//         component: () => import('@/views/appstore/components/CreateServiceGroup.vue'),
//         name: 'CreateServiceGroup',
//         meta: {
//           title: '创建服务组',
//           // if do not set roles, means: this page does not require permission
//           noCache: true,
//           activeMenu: '/appstore/service-group'
//         },
//         hidden: true
//       },
//       {
//         path: 'service-group-deploy',
//         component: () => import('@/views/appstore/components/ServiceGroupDeployComponents/ServiceGroupDeploy.vue'),
//         name: 'ServiceGroupDeploy',
//         meta: { title: '服务组部署', noCache: true, activeMenu: '/appstore/service-group' },
//         hidden: true
//       },
//       {
//         path: 'role',
//         component: () => import('@/views/appstore/role'),
//         name: 'RolePermission',
//         meta: {
//           title: '中间件'
//         }
//       }
//     ]
//   },
//   {
//     path: '/application-manage',
//     component: Layout,
//     redirect: '/application-manage/service-list',
//     alwaysShow: true, // will always show the root menu
//     name: 'ApplicationManage',
//     meta: {
//       title: '应用管理',
//       icon: 'lock'
//     },
//     children: [
//       {
//         path: 'service-list',
//         component: () => import('@/views/ApplicationManage/ServiceList.vue'),
//         name: 'ServiceList',
//         meta: {
//           title: '服务管理'
//         }
//       },
//       {
//         path: 'service-group-list',
//         component: () => import('@/views/ApplicationManage/ServiceGroupManage/ServiceGroupList.vue'),
//         name: 'ServiceGroupList',
//         meta: {
//           title: '服务组管理'
//         }
//       }
//     ]
//   },
//   {
//     path: '/storage-manage',
//     component: Layout,
//     redirect: '/storage-manage/storage-class-manager',
//     alwaysShow: true, // will always show the root menu
//     name: 'StorageManage',
//     meta: {
//       title: '存储管理',
//       icon: 'lock'
//     },
//     children: [
//       {
//         path: 'storage-class-manager',
//         component: () => import('@/views/storageManage/StorageClassManage.vue'),
//         name: 'StorageClassManage',
//         meta: {
//           title: '存储类管理'
//         }
//       },
//       {
//         path: 'persistent-volume-claim',
//         component: () => import('@/views/storageManage/PersistentVolumeClaim.vue'),
//         name: 'PersistentVolumeClaim',
//         meta: {
//           title: '持久卷声明'
//         }
//       }
//     ]
//   },
//   {
//     path: '/dependence-manage',
//     component: Layout,
//     redirect: '/dependence-manage/data-dependence',
//     alwaysShow: true, // will always show the root menu
//     name: 'DependenceManage',
//     meta: {
//       title: '依赖管理',
//       icon: 'lock'
//     },
//     children: [
//       {
//         path: 'data-dependence',
//         component: () => import('@/views/dashboard/index'),
//         name: 'DataDependence',
//         meta: {
//           title: '数据单元管理'
//         }
//       },
//       {
//         path: 'out-service-dependence',
//         component: () => import('@/views/dashboard/index'),
//         name: 'OutServiceDependence',
//         meta: {
//           title: '外部服务管理'
//         }
//       }
//     ]
//   },
//   {
//     path: '/adjective-manage',
//     component: Layout,
//     redirect: '/adjective-manage/resources-overview',
//     alwaysShow: true, // will always show the root menu
//     name: 'AdjectiveManage',
//     meta: {
//       title: '高级管理',
//       icon: 'documentation'
//     },
//     children: [
//       {
//         path: 'resources-overview',
//         component: () => import('@/views/dashboard/index'),
//         name: 'ResourcesOverview',
//         meta: {
//           title: '资源总览'
//         }
//       },
//       {
//         path: 'image-manage',
//         component: () => import('@/views/dashboard/index'),
//         name: 'ImageManage',
//         meta: {
//           title: '镜像管理'
//         }
//       },
//       {
//         path: 'system-deploy',
//         component: () => import('@/views/dashboard/index'),
//         name: 'SystemDeploy',
//         meta: {
//           title: '系统配置'
//         }
//       }
//     ]
//   },
//   {
//     path: '/user-center',
//     component: Layout,
//     redirect: '/user-center/person-information',
//     alwaysShow: true, // will always show the root menu
//     name: 'UserCenter',
//     meta: {
//       title: '用户中心',
//       icon: 'user'
//     },
//     children: [
//       {
//         path: 'person-information',
//         component: () => import('@/views/dashboard/index'),
//         name: 'PersonInformation',
//         meta: {
//           title: '个人信息'
//         }
//       },
//       {
//         path: 'audit-log',
//         component: () => import('@/views/dashboard/index'),
//         name: 'AuditLog',
//         meta: {
//           title: '审计日志'
//         }
//       }
//     ]
//   },
//   {
//     path: '/monitor-warn',
//     component: Layout,
//     children: [
//       {
//         path: 'index',
//         component: () => import('@/views/dashboard/index'),
//         name: 'MonitorWarn',
//         meta: { title: '监控告警', icon: 'tab' }
//       }
//     ]
//   },
//   // {
//   //   path: '/error',
//   //   component: Layout,
//   //   redirect: 'noRedirect',
//   //   name: 'ErrorPages',
//   //   meta: {
//   //     title: 'Error Pages',
//   //     icon: '404'
//   //   },
//   //   children: [
//   //     {
//   //       path: '401',
//   //       component: () => import('@/views/error-page/401'),
//   //       name: 'Page401',
//   //       meta: { title: '401', noCache: true }
//   //     },
//   //     {
//   //       path: '404',
//   //       component: () => import('@/views/error-page/404'),
//   //       name: 'Page404',
//   //       meta: { title: '404', noCache: true }
//   //     }
//   //   ]
//   // },

//   // {
//   //   path: '/error-log',
//   //   component: Layout,
//   //   children: [
//   //     {
//   //       path: 'log',
//   //       component: () => import('@/views/error-log/index'),
//   //       name: 'ErrorLog',
//   //       meta: { title: 'Error Log', icon: 'bug' }
//   //     }
//   //   ]
//   // },

//   // 404 page must be placed at the end !!!
//   { path: '*', redirect: '/404', hidden: true }
// ]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
